<template>
	<view class="page">
		<view class="item" v-for="(item, index) in list" :key="index">
			<view class="info" @click="goto(item)">
				<view class="title-time">
					<view class="title">
						{{item.title}}
					</view>
					<view class="time">
						{{item.createTime}}
					</view>
				</view>
				<view class="content">
					{{item.context}}
				</view>
			</view>
		</view>
		<view v-if="list.length===0" class="no-data">
			<image src="https://www.innovationgloble.com/wxs/img/wx/no-data.png"></image>
			<view class="no-data-text">暂无通知</view>
		</view>
		<view class="sysBottomShow" v-if="isLastPage">
			我是有底线的
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup_box">
				<view class="popup_box_title">
					提示
				</view>
				<view class="popup_box_content">
					<image src="../../static/gotopc.png" mode=""></image>
					<view class="popup_box_content_text">
						请登录PC端查看
					</view>
					<view class="popup_box_content_url">
						https://www.innovationgloble.com
					</view>
				</view>
				<view class="popup_box_btn" @click="closePopup">
					确定
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				list: [],
				pageNum:1,
				isLastPage:false
			}
		},
		onLoad() {
			this.loadList();
			this.clearSysMessage();
		},
		// computed: {
		// 	list() {
		// 		return this.notifyData.list;
		// 	}
		// },
		onPullDownRefresh() {
			this.isLastPage = false
			this.list = []
			this.pageNum = 1
			this.loadList();
		},
		onReachBottom() {
			if (!this.isLastPage) {
				this.pageNum += 1;
				this.loadList()
			}
		},
		methods: {
			...mapMutations('chatStore', ['clearSysMessage']),
			loadList() {
				uni.showLoading({
					title:'加载中'
				})
				this.$request.get({
					url: 'sysMessage/list',
					data: {
						pageSize: 10,
						pageNum: this.pageNum,
						messageType: 1
					}
				}).then(res => {
					uni.hideLoading()
					uni.stopPullDownRefresh();
					console.log('notifyData ', res);
					this.isLastPage = res.isLastPage
					this.list = [...this.list,...res.list];
				})
			},
			goto(v) {
				if (v.linkItemType == 'project') {
					if (v.approvalState == 1) {
						uni.navigateTo({
							url: '../../pages/project-detail/project-detail?scene=' + v.linkItemId
						})
					} else {
						this.openPopup()
					}

				} else if (v.linkItemType == "activities") {
					if (v.approvalState == 1) {
						uni.navigateTo({
							url: '../../pages/activity-detail/activity-detail?scene=' + v.linkItemId
						})
					} else {
						this.openPopup()
					}

				} else if (v.linkItemType == "expert") {
					if (v.approvalState == 1) {
						uni.navigateTo({
							url: '../../pages/expert-detail/expert-detail?scene=' + v.linkItemId
						})
					} else {
						uni.navigateTo({
							url: '../../pagesB/verify/verify'
						})
					}
				}else if (v.linkItemType == "agent"||v.linkItemType == "company") {
					uni.navigateTo({
						url: '../../pagesB/verify/verify'
					})
				} else {
					this.openPopup()
				}
			},
			openPopup() {
				this.$refs.popup.open()
			},
			closePopup() {
				this.$refs.popup.close()
			},
		}
	}
</script>

<style scoped lang="less">
	.page {
		width: 100%;
		min-height: 100vh;
		background-color: #fff;

		.no-data {
			display: flex;
			flex: 1;
			justify-content: center;
			align-items: center;
			min-height: 100vh;
			padding-bottom: 300upx;
			flex-flow: column;

			image {
				width: 240upx;
				height: 166upx;
			}

			.no-data-text {
				color: #666666;
				font-size: 26rpx;
				margin: 30rpx 0;
			}
		}

		.item {
			min-height: 214upx;
			display: flex;
			flex-direction: row;
			align-items: center;
			padding-left: 32upx;

			.img {
				width: 74upx;
				height: 74upx;
				margin-right: 24upx;
			}

			.info {
				flex: 1;
				display: flex;
				flex-direction: column;
				height: 100%;
				border-bottom: solid 1px #F5F5F5;
				padding: 32upx;
				box-sizing: border-box;

				.title-time {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					height: 100%;

					.title {
						font-size: 30upx;
						color: #444444;
					}

					.time {
						font-size: 22upx;
						color: #C5C4C4;
					}
				}

				.content {
					color: #888787;
					font-size: 28upx;
					word-break: break-all;
				}
			}
		}
		.popup_box {
			width: 540upx;
			height: 622upx;
			background: rgba(255, 255, 255, 1);
			border-radius: 24upx;
		
			.popup_box_title {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 83upx;
				color: #030303;
				font-weight: bold;
				border-bottom: 1px solid #E5E5E5;
			}
		
			.popup_box_content {
				text-align: center;
		
				image {
					width: 278upx;
					height: 199upx;
					margin: 49upx 0 38upx;
				}
		
				.popup_box_content_text {
					font-size: 24upx;
					color: #6F6F6F;
				}
		
				.popup_box_content_url {
					color: #2A7DFA;
					font-size: 26upx;
					text-decoration: underline;
				}
			}
		
			.popup_box_btn {
				width: 191upx;
				height: 66upx;
				background: rgba(42, 125, 250, 1);
				border-radius: 33upx;
				// display: inline-block;	
				// margin: 0 auto;
				color: #FFFFFF;
				margin: 56upx auto 0;
				font-size: 32upx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
